Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Cómo manejar múltiples casillas de verificación con el valor predeterminado marcado usando el estado con alguna matriz de objetos [React-JS Typescript]

estoy usando la casilla de verificación de entrada múltiple para mi entrada de formulario en reaccionar. como la imagen de abajo:

ingrese la descripción de la imagen aquí

esta es una parte de mi código:

 interface CheckType { id: any; desc: string; checked: boolean; } interface CheckListInputProps { options: Array<CheckType>; onChange: (e: React.ChangeEvent<HTMLInputElement>, data: Array<CheckType>) => void } const CheckListInput: React.FC<CheckListInputProps> = ({options, onChange}) => { const [initOpt, setInitOpt] = useState<Array<CheckType>([]) useEffect(()=>{ setInitOpt(options); },[options]) const changeHandler = (e: React.ChangeEvent<HTMLInputElement>) => { let {value, checked} = e.currentTarget let index = initOpt.findIndex(item => item.id===value); initOpt[index].checked = checked setInitOpt(initOpt) onChange(e, initOpt); } return ( <div> { initOpt.map((item, index) => ( <div key={index}> <input value={item.id} checked={item.checked} onChange={changeHandler}/> <label>{item.desc}</label> </div> )} </div>) }

cuando llamé a esta función en otro archivo:

 const ChangeHandler = (e: React.ChangeEvent<HTMLInputElement>, data: Array<any>) => { console.log(data); } const options = [ {id: 0, desc: "GET", checked: false}, {id: 1, desc: "POST", checked: false}, {id: 2, desc: "DELETE", checked: false} ] return <CheckListInput options={options} onChange={ChangeHandler}/

todo funciona bien el registro muestra lo que quiero. pero el problema está en la interfaz, la casilla de verificación no cambiará a marcada o desmarcada. ¿Cómo puedo solucionar esto? ¿Hay algún problema con esto checked={item.checked}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!